<template>
  <div class="container">
    <div class="opt-area-02">
      <div class="left-con">
        <div class="input-frame" style="width: 164px" v-if="severUserInfo.company_grade!=='5'">
          <Select placeholder="请选择区" :disabled="Adisabled" v-model="params.area_id" style="width:164px" @on-change="findDistrictList(3,params.area_id)">
            <Option v-for="item in List1" :value="item.id" :key="item.id">{{ item.name }}</Option>
          </Select>
        </div>
        <div class="input-frame" style="width: 164px" v-if="severUserInfo.company_grade!=='5'">
          <Select placeholder="请选择街道" :disabled="Bdisabled" v-model="params.street_id" style="width:164px">
            <Option v-for="item in List2" :value="item.id" :key="item.id">{{ item.name }}</Option>
          </Select>
        </div>
<!--        <div class="input-frame" style="width: 164px" v-if="severUserInfo.company_grade!=='5'">-->
<!--          <Select placeholder="请选择社区" v-model="params.community_id" style="width:164px">-->
<!--            <Option v-for="item in List3" :value="item.id" :key="item.id">{{ item.name }}</Option>-->
<!--          </Select>-->
<!--        </div>-->
        <div class="input-frame" style="width: 164px">
          <Select v-model="params.hspc_table_name" placeholder="核酸轮次" filterable>
            <Option v-for="obj in dicList" :value="obj.value" :key="obj.id">{{obj.label}}</Option>
          </Select>
        </div>
        <Button type="info" @click="seletData()" style="margin-top: 0px;margin-right:10px">搜索</Button>
      </div>
    </div>
    <Table :columns="tableColumns" :data="tableData" sum-text="合计" show-summary></Table>
</div>
</template>

<script>
import { findHSTJList, findSubordinateList } from '../../../api/eventlist'
import { findLabelList } from '@/api/grid'
export default {
  name: 'index',
  data () {
    return {
      severUserInfo: {},
      Adisabled: false,
      Bdisabled: false,
      List1: [],
      List2: [],
      List3: [],
      params: {
        area_id: '',
        street_id: '',
        // community_id: '',
        hspc_table_name: '0'
      },
      dicList: [],
      tableColumns: [
        { title: '区划', key: 'name', align: 'center' },
        { title: '推送数', key: 'ts', align: 'center' },
        { title: '处置数', key: 'cz', align: 'center' }
      ],
      tableData: []
    }
  },
  methods: {
    init () {
      if (this.severUserInfo.company_grade === '2') {
        let data = {
          groupBy: 'area',
          hspc_table_name: this.params.hspc_table_name
        }
        this.findTableList(data)
      }
      if (this.severUserInfo.company_grade === '3') {
        let data = {
          groupBy: 'street',
          area_id: this.params.area_id,
          hspc_table_name: this.params.hspc_table_name
        }
        this.findTableList(data)
      }
      if (this.severUserInfo.company_grade === '4') {
        let data = {
          groupBy: 'community',
          street_id: this.params.street_id,
          hspc_table_name: this.params.hspc_table_name
        }
        this.findTableList(data)
      }
      if (this.severUserInfo.company_grade === '5') {
        this.$Notice.error({ title: '查询失败', desc: '社区帐号无法使用此功能！' })
      }
    },
    seletData () {
      if (this.params.area_id !== '' && this.params.street_id !== '') {
        let data = {
          groupBy: 'community',
          street_id: this.params.street_id,
          hspc_table_name: this.params.hspc_table_name
        }
        this.findTableList(data)
      }
      if (this.params.area_id !== '' && (this.params.street_id === '' || this.params.street_id === undefined)) {
        let data = {
          groupBy: 'street',
          area_id: this.params.area_id,
          hspc_table_name: this.params.hspc_table_name
        }
        this.findTableList(data)
      }
      if ((this.params.area_id === '' || this.params.area_id === undefined) && (this.params.street_id === '' || this.params.street_id === undefined)) {
        let data = {
          groupBy: 'area',
          hspc_table_name: this.params.hspc_table_name
        }
        this.findTableList(data)
      }
    },
    findTableList (e) {
      let data = e
      console.log(data)
      findHSTJList(data).then(ret => {
        if (ret.data.errcode === 0) {
          this.tableData = ret.data.data
        } else {
          this.$Notice.error({
            title: '查询失败',
            desc: ret.data.errmsg
          })
        }
      })
    },
    findDistrictList (e1, e2) {
      let data = {
        grade: e1,
        id: e2
      }
      findSubordinateList(data).then(ret => {
        if (ret.data.errcode === 0) {
          if (e1 === 2) {
            this.List1 = ret.data.data
          } else if (e1 === 3) {
            this.List2 = ret.data.data
          } else if (e1 === 4) {
            this.List3 = ret.data.data
          }
        } else {
          this.$Notice.error({
            title: '查询失败',
            desc: ret.data.errmsg
          })
        }
      })
    },
    getDicInfo () {
      findLabelList().then(ret => {
        if (ret.data.errcode === 0) {
          this.dicList = ret.data.data
          this.params.hspc_table_name = this.dicList[this.dicList.length - 1].value
          this.init()
        } else {
          this.$Notice.error({ title: '查询核酸检测轮次失败', desc: ret.data.errmsg })
        }
      })
    }
  },
  mounted () {
    this.severUserInfo = this.$store.state.user.severUserInfo
    this.getDicInfo()
  },
  watch: {
    'severUserInfo.company_grade' (val) {
      if (val === '2') {
        this.findDistrictList(2, '999999999')
      } else if (val === '3') {
        this.findDistrictList(2, '999999999')
        this.params.area_id = this.severUserInfo.company_id
        this.findDistrictList(3, this.params.area_id)
        this.Adisabled = true
      } else if (val === '4') {
        this.findDistrictList(2, '999999999')
        this.params.area_id = this.severUserInfo.parent_id
        this.findDistrictList(3, this.params.area_id)
        this.params.street_id = this.severUserInfo.company_id
        this.findDistrictList(4, this.params.street_id)
        this.Adisabled = true
        this.Bdisabled = true
      }
    }
  }
}
</script>

<style scoped>
.page_style {
  margin: 20px 5px;
}

.input-frame {
  width: 120px;
  margin-right: 10px;
  float: left;
}

.house-list > .group {
  background: white;
  padding: 10px;
  margin-top: 10px;
}

.house-list > .group > .item {
  border-bottom: 1px solid #f5f5f5;
  padding: 10px 0;
}

.house-list > .group > .item .top {
  display: flex;
  justify-content: space-between;
  margin-bottom: 5px;
}

.house-list > .group > .item .title {
  font-size: 14px;
  color: #333333;
}

.house-list > .group > .item .address {
  font-size: 12px;
  color: gray;
  display: flex;
  align-items: center;
}

.house-list > .group > .item .detail {
  font-size: 12px;
  color: dodgerblue;
}

.opt-area-02 {
  display: flex;
  align-items: center;
  flex-direction: column;
  border: 1px solid #abdcff;
  background-color: #f0faff;
  padding: 8px 16px 8px 16px;
  border-radius: 4px;
  margin-bottom: 10px;
}

.opt-area-02 .right-con {
  width: 100%;
  margin-top: 5px;
  display: flex;
}

.opt-area-02 .left-con {
  font-size: 14px;
  width: 100%;
}

.opt-area-02 .left-con span {
  font-weight: bold;
}

.opt-area-02 .right-con input {
  width: 150px;
  margin-right: 10px;
}

.opt-area-02 .right-con .input-frame {
  width: 200px;
  margin-right: 10px;
}

.table-action-btn {
  margin-bottom: 3px;
}
.container {
  padding: 12px;
}
.container >>> .ivu-btn-small {
  height: 24px;
  padding: 0 5px;
  font-size: 12px;
  border-radius: 3px;
}

.btn-action {
  margin-bottom: 10px;
}

.mp10 {
  margin-right: 10px;
}
.title-style {
  color: red;
}
.mb20 {
  margin-bottom: 20px;
}
.ivu-table-row {
  height: 57px;
}
.demo-spin-icon-load{
  animation: ani-demo-spin 1s linear infinite;
}
@keyframes ani-demo-spin {
  from { transform: rotate(0deg);}
  50%  { transform: rotate(180deg);}
  to   { transform: rotate(360deg);}
}
.red-star {
  font-family: SimSun;
  color: #f00;
  margin-right: 4px;
}
.demo-spin-col{
  height: 100px;
  position: relative;
  /*border: 1px solid #eee;*/
}
.container>>>.ivu-icon-ios-arrow-forward:before{
  color: black;
}
</style>
